package com.example.minio.controller;

import com.example.minio.config.MinioConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@CrossOrigin
@RequestMapping("/minio")
public class MinioController {


    @Autowired
    private MinioConfig minioConfig;

    // 上传
    @PostMapping("/upload")
    public Object upload(@RequestParam("file") MultipartFile multipartFile) throws Exception {
        return this.minioConfig.putObject(multipartFile);
    }

    // 下载文件
    @GetMapping("/download")
    public void download(@RequestParam("filePath") String filePath, @RequestParam("fileName") String fileName, HttpServletResponse response) throws Exception {
        this.minioConfig.download(filePath, fileName, response);
    }
}
